﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.pad
{
    public partial class StorageProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<StorageEntity> entryList = new List<StorageEntity>();

            StorageEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new StorageEntity();
                    entry.ReceiveNo = item[StorageEntity.RECEIVE_NO].ToString();
                    entry.ReceiveType = item[StorageEntity.RECEIVE_TYPE].ToString();
                    entry.ApproveStatus = item[StorageEntity.APPROVE_STATUS].ToString();
                    entry.JobNum = item[StorageEntity.JOB_NUM].ToString();
                    
                    entry.PartNum = item[StorageEntity.PART_NUM].ToString();
                    entry.OldPartNum = item[StorageEntity.OLD_PARTNUM].ToString();
                    entry.PartDescription = item[StorageEntity.PART_DESCRIPTION].ToString();
                    entry.PartQty = Convert.ToDecimal(item[StorageEntity.PART_QTY].ToString());
                    entry.ApplyQty = Convert.ToDecimal(item[StorageEntity.APPLY_QTY].ToString());
                    entry.TranQty = Convert.ToDecimal(item[StorageEntity.TRAN_QTY].ToString());
                    entry.NetWeight = Convert.ToDecimal(item[StorageEntity.NET_WEIGHT].ToString());
                    entry.DueDate = string.IsNullOrEmpty(item[StorageEntity.DUE_DATE].ToString()) ? SqlDateTime.Null : Convert.ToDateTime(item[StorageEntity.DUE_DATE].ToString());
                    entry.IUM = item[StorageEntity.IUM_S].ToString();
                    entry.WareHouseCode = item[StorageEntity.WARE_HOUSE_CODE].ToString();
                    entry.WareHouseDesc = item[StorageEntity.WARE_HOUSE_DESC].ToString();
              
                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
